﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bookkeeping.Core.Entities;
using FluentNHibernate.Mapping;

namespace Bookkeeping.Persistence.Mappings
{
    public class PostMap : ClassMap<Post>
    {
        public PostMap()
        {
            Id(x => x.Id);
            Map(x => x.DateTime).Not.Nullable();
            Map(x => x.Comment).Not.Nullable();
            Map(x => x.Amount).Not.Nullable();
            Map(x => x.Name).Not.Nullable();
            Map(x => x.Type).Not.Nullable();

            HasManyToMany<Tag>(x => x.Tags)
                .AsBag()
                .Access.CamelCaseField(Prefix.Underscore)
                .Table("Post_Tag")
                .ChildKeyColumn("TagId")
                .ParentKeyColumn("PostId")
                .Cascade.None();
                //.Cascade.DeleteOrphan();
        }
    }
}
